import React from "react";
import {Modal, View, Text} from "react-native";
import RootSiblingsManager from "react-native-root-siblings";
import Spinner from "./Spinner.tsx";

export type LoadingContainerProps = {
    description?: string;
};
const LoadingContainer = ({description}: LoadingContainerProps) => {
    return (
        <Modal visible={true} transparent={true} supportedOrientations={['portrait', 'landscape']}>
            <View
                style={{flex: 1, backgroundColor: "rgba(0,0,0,0.4)", alignItems: "center", justifyContent: "center"}}>
                <Spinner iconColor={"#f8f8f8"} textColor={"#f8f8f8"} description={description}/>
            </View>
        </Modal>
    );
};

const ModalLoding: any = {};
ModalLoding.sibling = null;
ModalLoding.show = (description?: string) => {
    if (ModalLoding.sibling) {
        ModalLoding.sibling.destroy();
    }

    ModalLoding.sibling = new RootSiblingsManager(<LoadingContainer description={description}/>);
    return ModalLoding.sibling;
};

ModalLoding.hide = () => {
    ModalLoding.sibling?.destroy();
};

export default ModalLoding;
